﻿Public Class ProjectForm

    Private Shared _ConnString As String = ""
    Private _EnglishWord24 As EnglishWord24

    Public Sub New(ByVal ConnString As String, ByVal 选择编号 As String)

        InitializeComponent()

        _ConnString = ConnString
        _EnglishWord24 = EnglishWord24.GetInstance(_ConnString)
        Me.选择编号 = 选择编号
    End Sub

    Private Sub ProectForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadData()
    End Sub

    Private Sub LoadData()
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.DataSource = _EnglishWord24.GetAllProject

        Me.DataGridView1.Rows(If(CInt(Me.选择编号) - 1 <= 0, 0, Int(Me.选择编号) - 1)).Selected = True
    End Sub
    ' 0001 002 00 004 005 006 007 008 009 最大只能保存九个

    Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        If Me.DataGridView1.Rows.Count = 0 Then
            Return
        End If
        If Me.DataGridView1.SelectedRows.Count = 0 Then
            Return
        End If

        If e.ColumnIndex = 3 Then
            Using frm As EnglishWord = New EnglishWord(_ConnString, Me.DataGridView1.Rows(Me.DataGridView1.SelectedRows(0).Index).Cells(0).Value.ToString)
                frm.ShowDialog()
                LoadData()
            End Using
        ElseIf e.ColumnIndex = 4 Then
            If System.Windows.Forms.MessageBox.Show("准备清除数据，是否继续？", "永胜单词发音库", Windows.Forms.MessageBoxButtons.OKCancel, Windows.Forms.MessageBoxIcon.Information, Windows.Forms.MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.OK Then
                _EnglishWord24.ClearEnglishWor(Me.DataGridView1.Rows(Me.DataGridView1.SelectedRows(0).Index).Cells(0).Value.ToString)
                LoadData()
            End If

        End If

    End Sub

    Private _选择编号 As String = "0"
    Public Property 选择编号() As String
        Get
            Return _选择编号
        End Get
        Set(ByVal value As String)
            _选择编号 = value
        End Set
    End Property

    Private Sub DataGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
        If Me.DataGridView1.Rows.Count = 0 Then
            Return
        End If
        If Me.DataGridView1.SelectedRows.Count = 0 Then
            Return
        End If

        If CInt(DataGridView1.Rows(Me.DataGridView1.SelectedRows(0).Index).Cells(2).Value.ToString) <= 0 Then
            Return
        Else
            选择编号 = Me.DataGridView1.SelectedRows(0).Cells(0).FormattedValue.ToString
            DialogResult = Windows.Forms.DialogResult.OK
            Me.Close()
        End If

    End Sub
End Class